﻿using System.Collections.Generic;
using DynConDevCorp.OpenArch.SmartData.Interfaces;

namespace DynConDevCorp.OpenArch.SmartData.Interfaces
{
    /// <summary>
    /// Type Safe Interface for collections of ISmartField objects which have a primary key.
    /// </summary>
    /// <typeparam name="TKey">
    /// The type of the primary key.
    /// </typeparam>
    /// <typeparam name="TItem">
    /// The type of the item contained in the collection. 
    /// Must be derived from ISmartField.
    /// </typeparam>
    public interface ISmartFieldKeyedCollection<TKey, TItem> : ISmartFieldCollection<TItem>
        where TItem : ISmartField
    {
        #region Public Instance Properties

        /// <summary>
        /// Gets the <see cref="ISmartField"/> instance with the specified key.
        /// </summary>
        /// <value></value>
        TItem this[TKey key] { get; }

        /// <summary>
        /// Gets the keys.
        /// </summary>
        /// <value>The keys.</value>
        IList<TKey> Keys { get; }

        #endregion

        #region Public Instance Methods

        /// <summary>
        /// Adds the specified key.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="item">The item.</param>
        void Add(TKey key, TItem item);

        /// <summary>
        /// Removes the specified key.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <returns></returns>
        bool Remove(TKey key);

        /// <summary>
        /// Determines whether [contains] [the specified key].
        /// </summary>
        /// <param name="key">The key.</param>
        /// <returns>
        /// 	<c>true</c> if [contains] [the specified key]; otherwise, <c>false</c>.
        /// </returns>
        bool Contains(TKey key);

        /// <summary>
        /// Gets the field item.
        /// </summary>
        /// <typeparam name="TReturn">The type of the ETUR n_ TYPE.</typeparam>
        /// <param name="key">The key.</param>
        /// <returns></returns>
        TReturn GetFieldItem<TReturn>(TKey key) where TReturn : ISmartField;

        /// <summary>
        /// Tries the get value.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="item">The item.</param>
        /// <returns></returns>
        bool TryGetValue(TKey key, out TItem item);

        /// <summary>
        /// Tries the get key.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="key">The key.</param>
        /// <returns></returns>
        bool TryGetKey(TItem item, out TKey key);

        /// <summary>
        /// Gets the key.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <returns></returns>
        TKey GetKey(TItem item);

        #endregion
    }
}